package com.igeek.web;

import com.igeek.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jerryHe
 * @create 2019-10-08 15:59
 */

@WebServlet("/activeServlet")
public class ActiveServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收激活码随机数
        String activeCode = request.getParameter("activeCode");
        UserService service = new UserService();
        //1.判断激活码是否一致
        boolean flag = service.checkActiveCode(activeCode);
        if(flag){
            //2.修改状态
            service.updateActiveCode(activeCode);
            //激活成功，跳转到登录页面
            response.sendRedirect("login.jsp");
        }else{
            //激活失败，跳转到注册页面
            response.sendRedirect("register.jsp");
        }

    }
}
